﻿import requests
from collections import Counter
#分析网页后可以get历史所有双色球中奖数据
url='https://datachart.500.com/ssq/history/newinc/history.php?start=03001'
#获取历史所有双色球中奖数据
response = requests.get(url)
response.encoding = 'utf-8'
re_text = response.text
#网页数据解析
re=re_text.split('<tbody id="tdata">')[1].split('</tbody>')[0]
result=re.split('<tr class="t_tr1">')[1:]
history_balls = []
for i in result:
    i=i.replace('<!--<td>2</td>-->','')
    row=i.split('</td>')
    for num in range(1,8):
        history_balls.append(row[num].split('>')[1].replace('&nbsp;',''))
red_balls1=[]
red_balls2=[]
red_balls3=[]
red_balls4=[]
red_balls5=[]
red_balls6=[]
blue_balls=[]
for i in range(0,len(history_balls),7):
    red_balls1.append(history_balls[i+0])
    red_balls2.append(history_balls[i+1])
    red_balls3.append(history_balls[i+2])
    red_balls4.append(history_balls[i+3])
    red_balls5.append(history_balls[i+4])
    red_balls6.append(history_balls[i+5])
    blue_balls.append(history_balls[i+6])
counter=Counter(red_balls1)    
print("红球1号:",counter,"\n")
counter=Counter(red_balls2)    
print("红球2号:",counter,"\n")
counter=Counter(red_balls3)    
print("红球3号:",counter,"\n")
counter=Counter(red_balls4)    
print("红球4号:",counter,"\n")
counter=Counter(red_balls5)    
print("红球5号:",counter,"\n")
counter=Counter(red_balls6)    
print("红球6号:",counter,"\n")
counter=Counter(blue_balls)    
print("篮球:",counter)
input()